//////////////////////////////////////////////////////////////////////////////////
//	 Copyright 2011 by Yosef Grabivker, ryuho@homenetworksoft.com
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//////////////////////////////////////////////////////////////////////////////////

#include "def.h"
#include <wx/thread.h>
#include "rtping.h"

struct CPingEngineObserver
{
	virtual void OnPingResult(int nItem, const PINGRESULT& result)=0;
};

class CPingEngine: protected wxThread
{
public:
								CPingEngine();
	virtual						~CPingEngine();

	void						Start();
	void						Stop();

	
	void						SetObserver(CPingEngineObserver* ptr) { m_ptrObserver=ptr; }
	void						SetPingList(const PINGDATALIST& lst);

protected:
	void						Reset();
	virtual void*				Entry();
	bool						GetJob(PingData& entry, int& idx);
	void						PingEng(const PingData& entry, int idx);

private:
	CPingEngineObserver*		m_ptrObserver;
	PINGDATALIST				m_lstPing;
	wxCriticalSection			m_csPing;

	volatile size_t				m_idx;
	volatile bool				m_bThreadRun;
	volatile bool				m_bWorking;
	CRTPing						m_pinger;
};